/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_DEVICE_CONFIG_H
#define SLE_DEVICE_CONFIG_H

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "sle_type_trans_utils.h"

#define SLE_DEVICE_ADDRESS_LEN 6
#define SLE_DEVICE_NAME_LEN 31
#define SLE_HOST_NAME_PRE_FIX "kh_sle_"
#define SLE_HOST_NAME_PRE_FIX_LEN strlen(SLE_HOST_NAME_PRE_FIX)

typedef enum {
    SLE_HOST_STATE_ENABLED = 0,
    SLE_HOST_STATE_ENABLING = 1,
    SLE_HOST_STATE_DISABLING = 2,
    SLE_HOST_STATE_DISABLED = 3,
    /** keep SLE_HOST_STATE_ERROR at the end of hostStatus */
    SLE_HOST_STATE_ERROR = 7
} SleDeviceState_t;
typedef uint8_t SleDeviceState;

#ifndef SleDeviceStateStr
#define SleDeviceStateStr(deviceState)                                          \
    deviceState == SLE_HOST_STATE_ENABLED ? "Enabled" :(                        \
    deviceState == SLE_HOST_STATE_ENABLING ? "Enabling" :(                      \
    deviceState == SLE_HOST_STATE_DISABLING ? "Disabling" :(                    \
    deviceState == SLE_HOST_STATE_DISABLED ? "Disabled" :(                      \
    deviceState == SLE_HOST_STATE_ERROR ? "Error" : "Unknown"       ))))
#endif

typedef enum {
    SLE_PUBLIC_ADDRESS_TYPE = 0,
    SLE_RANDOM_ADDRESS_TYPE = 6,
} SleDevAddrType_t;
typedef uint8_t SleDevAddrType;

typedef struct {
    SleDevAddrType addrType;
    uint8_t addr[SLE_DEVICE_ADDRESS_LEN];
} SleDeviceAddress;

typedef struct {
    //上层可通过接口配置参数
    uint16_t connectInterval;       // 默认连接间隔
    uint16_t connectTimeout;        // 默认超时时间
    uint16_t connectLatency;        // 默认从机时延
    uint32_t mtuSize;               // 默认MTU大小
    //上层不可配置参数
    uint8_t mcs;                    // 默认MAC
    uint8_t pilotDensity;           // 默认导频密度
    uint8_t formatType;             // 默认无线帧类型
    uint16_t dataLen;               // 默认默认为MTU大小 + 10
    uint8_t phy;                    // 默认传输频宽
} SleConnectConfig;

typedef struct {
    uint8_t workMode;               //工作模式, 0:单配置模式; 1:步进模式; 2:自适应模式
    uint16_t stepCount;              //步长
    uint16_t stepPeriod;            //连接间隔递增
    uint8_t configMode;             //参数配置模式, 即[mode*], 0:high_speed; 1:normal_speed; 2:low_speed
} SleConnectModeConfig;

/**
 * @if Eng
 * @brief Struct of Default sle connection parameter.
 * @else
 * @brief 星闪默认连接参数
 * @endif
 */
typedef struct {
    uint8_t  enable_filter_policy;      /*!< @if Eng Whether the filtering function is enabled on the link
                                             @else 链路是否打开过滤功能 @endif */
    uint8_t  initiate_phys;             /*!< @if Eng Link scanning communication bandwidth: 1:1M, 2:2M
                                             @else 链路扫描通信带宽： 1:1M, 2:2M @endif */
    uint8_t  gt_negotiate;              /*!< @if Eng Whether G-T interaction is performed during link establishment
                                             @else 链路建立时是否进行G和T交互 @endif */
    uint16_t scan_interval;             /*!< @if Eng Interval for scanning the peer
                                                     device during link establishment
                                             @else 链路建立时扫描对端设备的interval @endif */
    uint16_t scan_window;               /*!< @if Eng Scans the Windows operating system of the
                                                     peer device during link establishment.
                                             @else 链路建立时扫描对端设备的windows @endif */
    uint16_t min_interval;              /*!< @if Eng Minimum link scheduling interval
                                             @else 链路调度最小interval @endif */
    uint16_t max_interval;              /*!< @if Eng Maximum link scheduling interval
                                             @else 链路调度最大interval @endif */
    uint16_t timeout;                   /*!< @if Eng Link Timeout Interval
                                             @else 链路超时时间 @endif */
} SleDefaultConnectionParam;


#ifndef SLE_DEFAULT_CONN_CONFIG
#define SLE_DEFAULT_CONN_CONFIG
#define DATA_LEN_BIGGER 10
#endif

#endif // SLE_DEVICE_CONFIG_H